package com.example.mybatisdemo.mapper;

import com.example.mybatisdemo.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface UserInfoMapper {
    @ResultMap("resultMap")
    @Select("select * from userinfo")
    List<UserInfo> getUserInfoAll();
    //参数传递
    @Select("select * from userinfo where id = #{id}")
    List<UserInfo> getUser(Integer id);
    @Select("select * from userinfo where id = #{ID}")
    List<UserInfo> getUser2(@Param("ID") Integer id);
    //增
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into userinfo(username,password,age,gender) "+
             "values (#{username},#{password},#{age},#{gender})")
    Integer insert(UserInfo userInfo);
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into userinfo(username,password,age,gender) "+
            "values (#{userInfo.username},#{userInfo.password},#{userInfo.age},#{userInfo.gender})")
    Integer insert2(@Param("userInfo") UserInfo userInfo);
    //删
    @Delete("delete from userinfo where id = #{id}")
    Integer delete(Integer id);
    //改
    @Update("update userinfo set password = #{password}, age = #{age}, gender = #{gender} where id = #{id}")
    Integer update(UserInfo userInfo);
    //查
    @Select("select * from userinfo")
    List<UserInfo> select();
    //起别名
    @Select("select id,username,password,age,gender,phone,create_time as createTime,update_time as updateTime from userinfo")
    List<UserInfo> select2();
    //结果映射
    @Results(id = "resultMap",value = {
            @Result(column = "create_time",property = "createTime"),
            @Result(column = "update_time",property = "updateTime"),
    })
    @Select("select * from userinfo")
    List<UserInfo> select3();
    //驼峰自动转换
    @Select("select * from userinfo")
    List<UserInfo> select4();
    //#{}与${}区别
    @Select("select * from userinfo order by id ${s}")
    List<UserInfo> order(String s);


}
